package Offer;

/**
 * @Author: wangliuyang
 * @Date: 2021/6/13 19:04
 * @Description: 剑指 Offer 42. 连续子数组的最大和
 */
public class Offer42 {
    public int maxSubArray(int[] nums) {
        int max = Integer.MIN_VALUE;
        int cur = 0;
        for (int i = 0; i < nums.length; i++) {
            cur += nums[i];
            max = Math.max(max,cur);
            cur = cur >= 0 ? cur : 0;
        }
        return max;
    }
}
